import { ApiProperty } from '@nestjs/swagger';
import { IsEnum, IsInt, IsOptional, IsString, Min } from 'class-validator';
import { Type } from 'class-transformer';

export enum SortOrder {
  RELEVANCE = 'relevance',
  LATEST = 'latest',
  POPULAR = 'popular',
}

export class SearchParamsDto {
  @ApiProperty({ description: '搜索关键词', required: true })
  @IsString()
  keyword: string;

  @ApiProperty({ description: '页码', default: 1 })
  @IsInt()
  @Min(1)
  @Type(() => Number)
  @IsOptional()
  page: number = 1;

  @ApiProperty({ description: '每页数量', default: 10 })
  @IsInt()
  @Min(1)
  @Type(() => Number)
  @IsOptional()
  limit: number = 10;

  @ApiProperty({ 
    description: '排序方式', 
    enum: SortOrder, 
    default: SortOrder.RELEVANCE
  })
  @IsEnum(SortOrder)
  @IsOptional()
  sort: SortOrder = SortOrder.RELEVANCE;
}